<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: price_change.php 97 2013-09-21 12:05:21Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 97 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2013-09-21 12:05:21 +0000 (Sat, 21 Sep 2013) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

require ('includes/application_top.php');

$sql = "SELECT 
			p.products_id,
			p.products_model,
			p.products_quantity,
			p.products_price,
			p.products_tax_class_id, 
			pd.products_name 
		FROM 
			".TABLE_PRODUCTS." p 
			LEFT JOIN ".TABLE_PRODUCTS_DESCRIPTION." AS pd ON (pd.products_id = p.products_id AND pd.language_id = '".$_SESSION['languages_id']."') ";

$query = page_break_create($_POST['per_site'], $_GET['page'], $sql, 'price_change.php');

if($_GET['action'] == 'save' && is_array($_POST['product'])) {

	foreach ($_POST['product'] AS $pid => $price) {
		if(isset($price) && $price !='') {
			$price = str_replace(',','.',$price);
			if($_POST['netto'] == 0){
				$tax_rate = $db->db_query(" SELECT products_tax_class_id FROM ".TABLE_PRODUCTS." WHERE products_id = '".(int)$pid."' ");
				$price = round(($price / ((get_tax_rate($tax_rate->fields['products_tax_class_id']) / 100) + 1 )), PRICE_PRECISION);
			}
			$db->db_query("UPDATE ".TABLE_PRODUCTS." SET products_price = '".$price."' WHERE products_id = '".(int)$pid."'");
		}
	}
	foreach ($_POST['products_quantity'] AS $pid => $products_quantity) {
		if(isset($products_quantity) && $products_quantity !='')
			$db->db_query("UPDATE ".TABLE_PRODUCTS." SET products_quantity = '".$products_quantity."' WHERE products_id = '".(int)$pid."'");
	}		
	foreach ($_POST['products_model'] AS $pid => $products_model)
		if(isset($products_model) && $products_model !='')
			$db->db_query("UPDATE ".TABLE_PRODUCTS." SET products_model = '".$products_model."' WHERE products_id = '".(int)$pid."'");

	redirect('price_change.php'.($_GET['page'] != '' ? '?page='.$_GET['page'] : ''));
}
require(DIR_WS_INCLUDES.'metatag.php'); ?>
</head>
<body>
<?php require(DIR_WS_INCLUDES.'header.php'); ?>
<div id="wrapper">
<table class="outerTable" cellspacing="0" cellpadding="0">
	<tr>
		<td class="columnLeft2" width="<?php echo BOX_WIDTH; ?>" valign="top">
			<?php require(DIR_WS_INCLUDES.'column_left.php'); ?>
		</td>
		<td class="boxCenter" valign="top">
			<table width="100%" cellspacing="0" cellpadding="0">
			  <tr>
				<td colspan="3">
					<table class="table_pageHeading" width="100%" cellspacing="0" cellpadding="0">
					  <tr>
						<td class="pageHeading">Schnelle Artikelpreis und -bestands&auml;nderung</td>
					  </tr>
					</table>
					<p>Geben Sie bei den gew&uuml;nschten Produkten den neuen Preis an. Auch gerne mehrere gleichzeitig. Danach am Ende der Seite die Art der Preiseingabe ausw&auml;hlen und abspeichern.</p>
				</td>
			</tr>
			<tr>
				<td align="center" colspan="3">
					<?php 
						echo draw_form('products', 'price_change.php', 'action=save'.(isset($_GET['page']) ? '&page='.$_GET['page'] : ''));
						if($_GET['page'] != '') echo draw_hidden_field('page', $_GET['page']);
					?>
						<table width="100%" class="dataTable" cellspacing="0" cellpadding="0">
							<tr class="dataTableHeadingRow">
								<td class="dataTableHeadingContent">ID</td>
								<td class="dataTableHeadingContent">Name</td>
								<td class="dataTableHeadingContent">Art-Nr</td>
								<td class="dataTableHeadingContent">alter Preis (netto)</td>
								<td class="dataTableHeadingContent">alter Preis (brutto)</td>
								<td class="dataTableHeadingContent">neuer Preis</td>
								<td class="dataTableHeadingContent">Bestand</td>
								<td class="dataTableHeadingContent">Bestand neu</td>
							</tr>
							<?php

							$products_data = $query['query'];

							while(!$products_data->EOF) {
								echo '<tr class="dataTableRow">';
								echo '<td class="categories_view_data">'.$products_data->fields['products_id'].'</td>';
								echo '<td class="categories_view_data" align="left" style="text-align:left">'.$products_data->fields['products_name'].'</td>';
								echo '<td class="categories_view_data">'.draw_input_field('products_model['.$products_data->fields['products_id'].']', $products_data->fields['products_model'],'size="12"').'</td>';
								echo '<td class="categories_view_data" style="text-align:left">'.format_price($products_data->fields['products_price'],1,$_SESSION['currency'],0,0).'</td>';
								echo '<td class="categories_view_data" style="text-align:left">'.format_price(round(($products_data->fields['products_price'] * ((get_tax_rate($products_data->fields['products_tax_class_id']) / 100) + 1)), PRICE_PRECISION),1,$_SESSION['currency'],0,0).'</td>';
								echo '<td class="categories_view_data" style="text-align:left">'.draw_input_field('product['.$products_data->fields['products_id'].']','','size="12"').'</td>';
								echo '<td class="categories_view_data" align="center" style="text-align:left">'.$products_data->fields['products_quantity'].'</td>';
								echo '<td class="categories_view_data" style="text-align:left">'.draw_input_field('products_quantity['.$products_data->fields['products_id'].']','','size="12"').'</td>';
								echo '</tr>';
								$products_data->MoveNext();
							}
							?>
						</table>
						<table width="100%">
							<tr>
								<td align="right"> <br />
									<table width="250px">
										<tr>
											<td>
												<strong>Art der Preiseingabe</strong><br />
												<input type="radio" name="netto" value="1" checked="checked"/> Netto <br />
												<input type="radio" name="netto" value="0" /> Brutto
											</td>
											<td valign="bottom" align="right">
												<button type="submit" class="button"><?php echo BUTTON_SAVE ?></button>
											</td>
										</tr>
									</table>
								</td>
							</tr>
						</table>
					</form>
				</td>
				</tr>
				<tr>
					<td colspan="3">&nbsp;</td>
				</tr>
				<tr class="page_break">
					<td class="smallText" valign="top" width="33.3%"><?php echo 'Angezeigt werden '.$query['from'].' bis '.$query['to'].' (von insgesamt '.$query['total'].' Artikeln)'; ?></td>
					<td class="smallText" align="center" width="33.3%"></td>
					<td class="smallText" align="right" width="33.3%">
						Produkte pro Seite: <?php echo $query['page_break']->perSiteDropdown($_GET['page']); ?>
					</td>
				</tr>
				<tr><td align="center" colspan="3"><?php echo '<br />'.$query['links']; ?></td></tr>
			</table>
		</td>
	</tr>
</table>
</div>
<?php require(DIR_WS_INCLUDES.'footer.php'); ?>
</body>
</html>
<?php require(DIR_WS_INCLUDES.'application_bottom.php'); ?>